<?php
namespace App\Repositories;

use App\Message;
use App\Repositories\BaseRepository;
use App\Scopes\StatusScope;

class MessageRepository {
	use BaseRepository;

	protected $model, $table_name;

	public function __construct(Message $message) {
		$this->model = $message;
		$this->table_name = 'messages';
	}

	protected function searchColumn($query, $where) {
		return $query->when(array_key_exists('name', $where), function ($query) use ($where) {
			return $query->whereHas('user', function ($query) use ($where) {
				return $query->withoutGlobalScope(StatusScope::class)->where('name', 'like', "%{$where['name']}%")->orWhere('nick_name', 'like', "%{$where['name']}%");
			});
		})->when(array_key_exists('content', $where), function ($query) use ($where) {
			return $query->where('content', 'like', "%{$where['content']}%");
		});
	}
}